package Test;

public class setPriority {

    public static void main(String[] args) {

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "输出了：" + i);
                    if (i==2){
                        try {
                            Thread.sleep(500);  // 运用sleep使thread1进入休眠 ---- 阻塞状态
                            //Thread.yield();   // 使用yeild让步，使当前线程回到就绪状态，让其他优先级相同或更高的线程先运行
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        },"线程一");

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "输出了：" + i);
                }

            }
        },"线程二");

        thread1.setPriority(Thread.MAX_PRIORITY);
        thread2.setPriority(2);
        thread1.start();
        thread2.start();
    }

}
